/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-05-27 08:43:07
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-09-29 16:23:18
 * @FilePath: \linePatrol\vue-element-plus-admin\src\api\login\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from '@/axios'
import axios from 'axios'
import { useUserStore } from '@/store/modules/user'
import { ElMessage } from 'element-plus'


const service = axios.create({
  baseURL: import.meta.env.VITE_API_BASE_URL as string,
  timeout: 10000 //限制返回时长
})
console.log(import.meta.env.VITE_API_BASE_URL);

class AccountApi {
  async Sign(username: string, password: string): Promise<boolean> {
    const result = await service.post('/api/auth/login', {
      username: username,
      password: password
    })
    const { status, data } = result as any
    if (status == 200) {
      if (data.code == 200) {
        const userStore = useUserStore()
        userStore.setToken(data.data.access_token)
        return true
      } else {
        ElMessage.error(data.msg)
        return false
      }
    } else {
      return false
    }
  }
}
export default new AccountApi()
